package com.example.enews.activities

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.example.enews.R
import com.example.enews.databinding.ActivityNewsDetailBinding
import com.example.enews.models.News

class NewsDetailActivity : AppCompatActivity() {
    private lateinit var binding: ActivityNewsDetailBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityNewsDetailBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val news = intent.getParcelableExtra<News>("news") ?: run {
            Toast.makeText(this, "无法加载新闻详情", Toast.LENGTH_SHORT).show()
            finish()
            return
        }

        binding.tvNewsDetailTitle.text = news.title
        binding.tvNewsDetailCategory.text = news.category
        binding.tvNewsDetailDate.text = news.date
        binding.tvNewsDetailContent.text = news.content

        // 使用Glide标准API加载图片
        Glide.with(this)
            .load(news.imageUrl)
            .placeholder(R.drawable.placeholder_image)
            .error(R.drawable.error_image)
            .into(binding.ivNewsDetailImage)
    }
}
